<!-- 收藏 -->
<template>
	<view class="collect-page" style="height: calc(100vh - 44px);">
		<view class="items" style="height: 360rpx;background-color: rgb(247, 248, 250);padding: 10rpx 0;" v-for="v,k in good">
			<p style="font-weight: bold;margin-left: 40rpx;margin-top: 20rpx;">{{v.supplierName}}</p>
			<van-card
			  :num="v.count"
			  :price="v.price"
			  :desc="v.effect"
			  :title="v.name"
			  :thumb="v.image"
			/>
			<view style="position: relative;left: 220px;">
				<van-button round type="default" size="small" 
				style="margin-right: 20rpx;" @click="ondel(v.id)">删除商品</van-button>
				<van-button round type="primary" size="small"
				 @click="gocart(v)">立即购物</van-button>
			</view>
		</view>
		<p style="text-align: center;padding: 20rpx 0;">没有更多数据了~</p>
	</view>
	
</template>

<script setup>
import {
		ref, watch
	} from 'vue';
	import {
		showToast
	} from 'vant';
	import {
		useStore
	} from 'vuex'
	import {
		onLoad,onShow
	} from '@dcloudio/uni-app';
	import api from './../../lib/request.js'
	const store = useStore()
	let id = ref(store.state.uid)
	let good = ref([])
	//初始化
	api.get(`/collect/findAll/${id.value}`).then(res=>{
		good.value = res.data
	})
	//删除
	function ondel(id){
		console.log(id);
		api.del(`/collect/delete/${id}`).then(res=>{
			if(res.code){
				showToast('删除成功')
				good.value = res.data
			}
		})
	}
	//去购物
	function gocart(v){
		let a = []
		a.push(v)
		store.commit('update_good',a)
		store.commit('update_price',v.price)
		uni.navigateTo({
			url:'/pages/checkout/checkout'
		})
	}
</script>

<style>
.items{
	margin: 20rpx 0 ;
}
</style>
